/**
 * Created by Administrator on 2017/3/7 0007.
 */
var Page0= {
    create: function () {
        var page = {};

        var tw_t0,tw_t1,tw_t2,tw_bg,tw_cover,tw_whole;

        page.ui=new PIXI.DisplayObjectContainer();
        var bg=new PIXI.Sprite(resource['assets/images/page0_bg.png'].texture);
        bg.alpha=1;
        page.ui.addChild(bg);

        var bgCover=new PIXI.Sprite(resource['assets/images/page0_cover.png'].texture);
        bgCover.alpha=0;
        page.ui.addChild(bgCover);

        var t0y=184;
        var t0=new PIXI.Sprite(resource['assets/images/page0_t0.png'].texture);
        t0.x=550;
        t0.y=t0y;
        t0.alpha=0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);

        var t1y=287;
        var t1=new PIXI.Sprite(resource['assets/images/page0_t1.png'].texture);
        t1.x=565;
        t1.y=t1y;
        t1.alpha=0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        var t2=new PIXI.Sprite(resource['assets/images/page0_t2.png'].texture);
        t2.x=1045;
        t2.y=570;
        t2.alpha=0;
        t2.anchor.set(0.5);
        page.ui.addChild(t2);

        page.In=function () {
            tw_bg=new TWEEN.Tween({alpha:0})
                .to({alpha:1},2000)
                .onUpdate(function () {
                    // bg.alpha=this.alpha;
                })
                // .easing(TWEEN.Easing.Cubic.In)
                .start();
            tw_cover=new TWEEN.Tween({alpha:0})
                .to({alpha:1},2000)
                .delay(100)
                .onUpdate(function () {
                    bgCover.alpha=this.alpha;
                })
                // .easing(TWEEN.Easing.Cubic.Out)
                .start();

            tw_t0=new TWEEN.Tween({alpha:0,y:t0y+30})
                .to({alpha:1,y:t0y},1000)
                .delay(500)
                .onUpdate(function () {
                    t0.alpha=this.alpha;
                    t0.y=this.y;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t1=new TWEEN.Tween({alpha:0,y:t1y+30})
                .to({alpha:1,y:t1y},1000)
                .delay(700)
                .onUpdate(function () {
                    t1.alpha=this.alpha;
                    t1.y=this.y;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t2=new TWEEN.Tween({alpha:0})
                .to({alpha:1},700)
                .onUpdate(function () {
                    t2.alpha=this.alpha;
                })
                .delay(1200)
                .easing(TWEEN.Easing.Cubic.Out)
                .start();
        };
        page.Out=function () {
            if(tw_t0)
            {
                tw_t0.stop();
                TWEEN.remove(tw_t0);
            }
            if(tw_t1)
            {
                tw_t1.stop();
                TWEEN.remove(tw_t1);
            }
            if(tw_t2)
            {
                tw_t2.stop();
                TWEEN.remove(tw_t2);
            }
            if(tw_bg)
            {
                tw_bg.stop();
                TWEEN.remove(tw_bg);
            }
            if(tw_cover)
            {
                tw_cover.stop();
                TWEEN.remove(tw_cover);
            }

            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},400)
                .onUpdate(function () {
                    // page.ui.alpha=this.alpha;
                })
                .onComplete(function () {
                    page.ui.alpha=1;
                    t0.alpha=0;
                    t1.alpha=0;
                    t2.alpha=0;
                    // bg.alpha=0;
                    bgCover.alpha=0;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }
        
        
        return page;
    }
}